package com.learn.controller;

import com.learn.controller.dto.Swagger3Req;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * swagger相关注解。参考地址https://github.com/swagger-api/swagger-core/wiki/Swagger-2.X---Annotations
 * · @Tag：控制器说明
 * · @Operation：请求说明
 * · @Parameter：单个参数说明
 * · @RequestPart：表单数据说明。结合consumes = MediaType.MULTIPART_FORM_DATA_VALUE
 */
@RestController
@Tag(name = "Swagger3控制器", description = "Swagger3控制器描述")
public class Swagger3Controller {
    @PostMapping("/swagger-get")
    @Operation(summary = "请求说明", description = "请求说明描述")
    @Parameter(name = "title", description = "描述", example = "哈哈", required = true)
    public String get(String title) {
        return "swagger-get";
    }
    
    @PostMapping("/swagger-post")
    @Operation(summary = "POST方法")
    public String post(@RequestBody @Validated Swagger3Req req) {
        return "swagger-post";
    }
    
    @PostMapping(value = "/swagger-upload", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    @Operation(summary = "文件上传")
    public String upload(@RequestPart("files") MultipartFile[] file) {
        return "swagger-upload";
    }
}
